/**
 * 活动api服务接口
 * @author lian
 */

import { ActivityApi } from '@/common/constants/request-api'
import { Method } from '@/common/enum/request-methods'
import type { Activity, ActivityDetail } from '@/common/types/activity'
import type { ActivityCreateParams, PagedParams, PagedResult } from '@/common/types/request'

/**
 * 随机获取五个活动
 * @author lian
 */
export const getRandomActivityService = () => {
  return useRequest<Activity[]>({
    method: Method.GET,
    url: ActivityApi.RANDOM_GET_FIVE_ACTIVITY,
  })
}

/**
 * 分页获取活动
 * @param pagedParams 分页参数
 * @author lian
 */
export const getPagedActivityService = (pagedParams: PagedParams) => {
  return useRequest<PagedResult<Activity[]>>({
    method: Method.GET,
    url: ActivityApi.PAGED_GET_ACTIVITY,
    data: {
      ...pagedParams,
    },
  })
}

/**
 * 根据活动id获取活动详情
 * @param activityId 活动id
 * @author lian
 */
export const getActivityDetailService = (activityId: number) => {
  const url = replaceParams(ActivityApi.GET_ACTIVITY_DETAIL, [
    {
      paramName: 'id',
      value: activityId,
    },
  ])

  return useRequest<ActivityDetail>({
    method: Method.GET,
    url,
  })
}

/**
 * 报名活动
 * @param activityId 活动id
 * @author lian
 */
export const signUpActivityService = (activityId: number) => {
  const url = replaceParams(ActivityApi.SIGN_UP_ACTIVITY, [
    {
      paramName: 'id',
      value: activityId,
    },
  ])

  return useRequest({
    method: Method.POST,
    url,
  })
}

/**
 * 取消报名活动
 * @param activityId 活动id
 * @author lian
 */
export const cancelSignUpActivityService = (activityId: number) => {
  const url = replaceParams(ActivityApi.CANCEL_SIGN_UP_ACTIVITY, [
    {
      paramName: 'id',
      value: activityId,
    },
  ])

  return useRequest({
    method: Method.GET,
    url,
  })
}

/**
 * 创建活动
 * @param data 活动信息
 * @author lian
 */
export const createActivityService = (data: ActivityCreateParams) => {
  return useRequest({
    method: Method.POST,
    url: ActivityApi.CREATE_ACTIVITY,
    data,
  })
}
